define(function(require, exports, module){
	require('common/util');
	require('valid/valid');
	exports.init = function(){
		//可以自己扩展验证规则
		$.extend(still.Valid.rules,{
	        passEQ:{
	            validator: function(value, param){
	                var passOne = $(this).closest('form').find('[name='+param[0]+']')[0];
	                return $(passOne).val()==value;
	            },
	            message: '两次密码输入必须一致！'
	        }
		});
		$.extend(still.Valid.asyncRules, {
	        checkname:{
	            validator:function(value,param){
	                var exist = false;
	                $.ajax({
	                    url: 'js/index/user.json',
	                    type: 'POST',
	                    dataType: 'json',
	                    data: {username: value},
	                    async:false,
	                    success: function(result){
	                        if(result['state']==2 && value=='admin'){
	                            exist = true;
	                        }
	                    }
	                });
	                return !exist;
	                
	            }, 
	            message:'用户名已存在！'
	        }
		});
		
		//给表单绑定验证
		$('#userAddForm').bindValid();
		//点击提交时出触发表单验证
		$('#formSubmit').click(function(){
			var isPass = $('#userAddForm').fireValid();
			if(isPass){
				alert('提交成功');
			}else{
				alert('验证未通过,请检查');
			}
		});
	}
})